//
//  CatImageView.m
//  UI_04homeworkTomCat
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CatImageView.h"

@implementation CatImageView

// 经写法遍历构造器不适合先注掉
+(instancetype)catImageViewWithImageName:(NSString *)imageName withImageSuffix:(NSString *)imageSuffix withStartNumber:(NSInteger)startNumber withImagesCounts:(NSInteger)imagesCounts
{

    NSMutableArray <UIImage *>*imagesArray = [NSMutableArray arrayWithCapacity:50];
    
    for (NSInteger i = 0; i < imagesCounts; i ++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%ld.%@", imageName, i +startNumber, imageSuffix]];
        NSLog(@"%@%ld.%@", imageName, i + startNumber, imageSuffix);
        [imagesArray addObject:image];
        [image release];
    }
    CatImageView *imageView = [[CatImageView alloc]init];
//    imageView.frame = CGRectMake(0, 0, 360, 630);
    imageView.animationImages = imagesArray;
    imageView.animationDuration = imagesCounts * 0.3;
    [imageView startAnimating];
    return [imageView autorelease];
    
    
    }



//再做一个好用的初始化吧...
-(instancetype)initWithImageName:(NSString *)imageName withImageSuffix:(NSString *)imageSuffix withStartNumber:(NSInteger)startNumber withImagesCounts:(NSInteger)imagesCounts
{
    NSMutableArray <UIImage *>*imagesArray = [NSMutableArray arrayWithCapacity:50];
    
    for (NSInteger i = 0; i < imagesCounts; i ++) {
        NSString *path = [[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%@%02ld", imageName, startNumber] ofType:imageSuffix];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        [imagesArray addObject:image];
    }
    self = [super init];
    if (self) {
        self.animationImages = imagesArray;
        self.animationDuration = imagesCounts * 0.3;
        [self startAnimating];
    }
    return self;
}



@end
